﻿Public Class Dossier

    'les propriete de la classe --------------------------------

    Public id As Integer
    Public Num As String
    Public Ref As Integer
    Public Tribunal As String
    Public Objet As String
    Public Grade As String
    Public Methode As String
    Public Type_appel As String
    Public Date_inscr_tribunal As String
    Public Etat_appel As String
    Public Archive As Boolean
    Public Remarque As String


    Public listverif As ArrayList
    'Les constructeur ---------------------------------------------

    Sub New(ByVal Id As Integer, ByVal Num As String, ByVal Tribunal As String, ByVal Objet As String, ByVal Grade As String, ByVal Methode As String, ByVal Type_appel As String, ByVal Date_inscr_tribunal As String, ByVal Etat_appel As String, ByVal Archive As Boolean, ByVal Remarque As String)
        Me.id = Id
        Me.Num = Num
        Me.Tribunal = Tribunal
        Me.Objet = Objet
        Me.Grade = Grade
        Me.Methode = Methode
        Me.Type_appel = Type_appel
        Me.Date_inscr_tribunal = Date_inscr_tribunal
        Me.Etat_appel = Etat_appel
        Me.Archive = Archive
        Me.Remarque = Remarque

    End Sub

    Sub New()

    End Sub

    'les Liste des relaltions---------------------------------------

    Public List_avocat_bureau As New ArrayList
    Public List_client As New ArrayList
    Public List_temoins As New ArrayList
    Public List_enemi As New ArrayList
    Public List_fichier_origine As New ArrayList
    Public List_khibra As New ArrayList
    Public List_pappier As New ArrayList
    Public List_decisions As New ArrayList
    Public List_depences As New ArrayList
    Public List_mo9arir As New ArrayList
    Public List_ijraa As New ArrayList
    Public List_avoca_partenaire As New ArrayList
    Public List_avocat_enemie As New ArrayList
    Public List_montant As New ArrayList
    Public List_Mokhabara As New ArrayList

    'les fonctions ---------------------

    Public Sub remplir_List_avoca_partenaire()
        Me.List_avoca_partenaire.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Dossiers_Avocat_Partonaire where  Id_Dossier =" & Me.id, Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Dossier_Avocat_Partenaire(Partager.dr("Id_Dossier"), Partager.dr("Id_Avocat_Partonaire"), Partager.dr("nomme"))
            Me.List_avoca_partenaire.Add(khab)
        End While
        Partager.close()
    End Sub

    Public Sub suprimmer_avoca_partenaire(ByVal id As Integer)
        Dim cmd As New SqlClient.SqlCommand("delete  Dossiers_Avocat_Partonaire where Id_Avocat_Partonaire =" & id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_avoca_partenaire()
    End Sub

    Public Sub Ajouter_avoca_partenaire(ByVal ad As Dossier_Avocat_Partenaire)
        Dim cmd As New SqlClient.SqlCommand("insert into Dossiers_Avocat_Partonaire values(" & Me.id & "," & ad.Id_Avocat_Part & ",1,GETDATE())", Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_avoca_partenaire()
    End Sub

    Public Sub modifierAvoPartNomme(ByVal ad As Dossier_Avocat_Partenaire)
        Dim str As String = "0"
        If ad.nomme Then
            str = "1"
        End If
        Dim cmd As New SqlClient.SqlCommand("update Dossiers_Avocat_Partonaire set nomme=" & str _
        & "where Id_Avocat_Partonaire= " & ad.Id_Avocat_Part & "and Id_Dossier=" & ad.Id_Dossier, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        remplir_List_avocat_bureau()
    End Sub

    Public Sub modifierAvoNomme(ByVal ad As dossAvoBur)
        Dim str As String = "0"
        If ad.nomme Then
            str = "1"
        End If
        Dim cmd As New SqlClient.SqlCommand("update Dossiers_Avocat_Bureau set nomme=" & str _
        & "where Id_Avocat_Bureau= " & ad.idAvoBur & "and Id_Dossier=" & ad.idDoss, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        remplir_List_avocat_bureau()
    End Sub


    Public Sub remplir_List_client()
        Me.List_client.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Dossiers_Clients where  Id_Dossier =" & Me.id, Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Dossiers_Clients(Partager.dr("id_Dossier"), Partager.dr("Id_Clients"), Partager.dr("type"))
            'khab.remplir_List_montant()
            Me.List_client.Add(khab)
        End While
        Partager.close()
    End Sub

    Public Sub suprimmer_client(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete FROM  Dossiers_Clients where Id_Dossier=" & Me.id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_client()
    End Sub

    Public Sub Ajouter_client(ByVal cd As Dossiers_Clients)

        Dim cmd As New SqlClient.SqlCommand("insert into Dossiers_Clients values(" & Me.id & "," & cd.Id_Clients & ",@type,GETDATE())", Partager.con)

        cmd.Parameters.Add("@type", SqlDbType.VarChar).Value = cd.type
        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_client()
    End Sub


    Public Sub remplir_List_enemi()
        Me.List_enemi.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Dossier_Adversaire where Id_Dossier =" & Me.id, Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Dossier_Adversaire(Partager.dr("id_Dossier"), Partager.dr("Id_Adversaire"), Partager.dr("type"))
            Me.List_enemi.Add(khab)
        End While
        Partager.close()
    End Sub

    Public Sub suprimmer_enemi(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete Dossier_Adversaire where Id_Dossier =" & id & " and Id_Dossier=" & Me.id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_enemi()


    End Sub

    Public Sub Ajouter_enemi(ByVal dosEn As Dossier_Adversaire)

        Dim cmd As New SqlClient.SqlCommand("insert into Dossier_Adversaire values(" & Me.id & "," & dosEn.Id_Adversaire & ",@type,GETDATE())", Partager.con)

        cmd.Parameters.Add("@type", SqlDbType.VarChar).Value = dosEn.type
        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_enemi()


    End Sub




    Public Sub remplir_List_fichier_origine()
        Me.List_fichier_origine.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Dossier_Original where Id_Dossier=" & Me.Id, Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New fichier_origin(Partager.dr("id"), Partager.dr("Num_Dossier"), Partager.dr("Num_Decision"), Partager.dr("Autorite"), Partager.dr("Date_Decision"), Partager.dr("Mo9arir"), Partager.dr("Tribunal"), Partager.dr("Remarque"))
            Me.List_fichier_origine.Add(khab)
        End While
        Partager.Close()
    End Sub

    Public Sub suprimmer_fichier_origine(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete from Dossier_Original where id=" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_fichier_origine()


    End Sub

    Public Sub Ajouter_fichier_origine(ByVal fich As fichier_origin)

        Dim cmd As New SqlClient.SqlCommand("insert into Dossier_Original values (" & Me.id & ",@Num_Dossier,@Num_Decision,@Autorite,@Date_Decision,@Mo9arir,@Tribunal,@Remarque,GETDATE())", Partager.con)
        cmd.Parameters.Add("@Num_Dossier", SqlDbType.VarChar).Value = fich.Num
        cmd.Parameters.Add("@Num_Decision", SqlDbType.VarChar).Value = fich.Num_decision
        cmd.Parameters.Add("@Autorite", SqlDbType.VarChar).Value = fich.autorie
        cmd.Parameters.Add("@Date_Decision", SqlDbType.Date).Value = fich.date_decision
        cmd.Parameters.Add("@Mo9arir", SqlDbType.VarChar).Value = fich.mo9arir
        cmd.Parameters.Add("@Tribunal", SqlDbType.VarChar).Value = fich.tribunal
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = fich.remarque

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_fichier_origine()


    End Sub

    Public Sub modifier_List_fichier_origine(ByVal idd As Integer, ByVal fich As fichier_origin)
        Dim cmd As New SqlClient.SqlCommand("update  Dossier_Original set Id_Dossier=@Id_Dossier,Num_Dossier=@Num_Dossier , Num_Decision=@Num_Decision , Autorite=@Autorite , Date_Decision=@Date_Decision,Mo9arir=@Mo9arir,Tribunal=@Tribunal,Remarque=@Remarque where id=" & idd, Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Num_Dossier", SqlDbType.VarChar).Value = fich.Num
        cmd.Parameters.Add("@Num_Decision", SqlDbType.VarChar).Value = fich.Num_decision
        cmd.Parameters.Add("@Autorite", SqlDbType.VarChar).Value = fich.autorie
        cmd.Parameters.Add("@Date_Decision", SqlDbType.VarChar).Value = fich.date_decision
        cmd.Parameters.Add("@Mo9arir", SqlDbType.VarChar).Value = fich.mo9arir
        cmd.Parameters.Add("@Tribunal", SqlDbType.VarChar).Value = fich.tribunal
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = fich.remarque

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_fichier_origine()

    End Sub



    Public Sub remplir_List_khibra()
        Me.List_khibra.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from  khibra where Id_Dossier=" & Me.Id, Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Khibra(Partager.dr("id"), Partager.dr("Num_Khibra"), Partager.dr("Date_Decision"), Partager.dr("Remarque"))
            'khab.remplir_list_depences_khibra()
            'khab.remplir_list_khabir()
            Me.List_khibra.Add(khab)
        End While
        Partager.Close()
    End Sub

    Public Sub suprimmer_khibra(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete from Khibra where id =" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_khibra()


    End Sub

    Public Sub Ajouter_khibra(ByVal khib As Khibra)

        Dim cmd As New SqlClient.SqlCommand("insert into Khibra values (@Id,@Num_Khibra,@Date_Decision,@Remarque,GETDATE())", Partager.con)

        cmd.Parameters.Add("@id", SqlDbType.Int).Value = Me.id
        cmd.Parameters.Add("@Num_Khibra", SqlDbType.VarChar).Value = khib.Num
        cmd.Parameters.Add("@Date_Decision", SqlDbType.Date).Value = khib.Date_decision
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = khib.Remarque


        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_khibra()


    End Sub

    Public Sub modifier_khibra(ByVal khib As Khibra, ByVal idd As Integer)

        Dim cmd As New SqlClient.SqlCommand("update  Khibra set Id_Dossier=@Id_Dossier,Num_Khibra=@Num_Khibra , Date_Decision=@Date_Decision , Remarque=@Remarque where id=" & idd, Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Num_Khibra", SqlDbType.VarChar).Value = khib.Num
        cmd.Parameters.Add("@Date_Decision", SqlDbType.DateTime2).Value = khib.Date_decision
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = khib.Remarque



        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        remplir_List_khibra()

    End Sub


    Public Sub remplir_List_pappier()
        Me.List_pappier.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Papiers where Id_Dossier=" & Me.Id, Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Pappier(Partager.dr("id"), Partager.dr("Nom"), Partager.dr("Nombre_pieces_jointes"), Partager.dr("Remarque"))
            Me.List_pappier.Add(khab)
        End While
        Partager.dr.Close()
        Partager.close()

    End Sub

    Public Sub suprimmer_pappier(ByVal pap As Pappier)

        Dim cmd As New SqlClient.SqlCommand("delete from Papiers where id=" & pap.id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
        For Each Piece As Jouinture In pap.List_jouiture
            My.Computer.FileSystem.DeleteFile(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "PieceJointe\" & Piece.Nom & Piece.Id & "." & Piece.ex)
        Next

        Me.remplir_List_pappier()


    End Sub

    Public Sub Ajouter_pappier(ByVal pap As Pappier)


        Dim cmd As New SqlClient.SqlCommand("insert into Papiers  values (@Id_Dossier,@Nom,@Nombre_pieces_jointes,@Remarque,GETDATE())", Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.Int).Value = Me.id
        cmd.Parameters.Add("@Nom", SqlDbType.VarChar).Value = pap.Nom
        cmd.Parameters.Add("@Nombre_pieces_jointes", SqlDbType.Int).Value = pap.Nombre
        cmd.Parameters.Add("@Remarque", SqlDbType.Text).Value = pap.Remarque


        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_pappier()


    End Sub

    Public Sub modifier_pappier(ByVal pap As Pappier, ByVal idd As Integer)

        Dim cmd As New SqlClient.SqlCommand("update  Papiers set Id_Dossier=@Id_Dossier,Nom=@Nom , Nombre_pieces_jointes=@Nombre_pieces_jointes , Remarque=@Remarque where id=" & idd, Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Nom", SqlDbType.VarChar).Value = pap.Nom
        cmd.Parameters.Add("@Nombre_pieces_jointes", SqlDbType.VarChar).Value = pap.Nombre
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = pap.Remarque


        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_pappier()

    End Sub



    Public Sub remplir_List_decisions()
        Me.List_decisions.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Decision where Id_Dossier=" & Me.Id, Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        If Partager.dr.HasRows Then
            While Partager.dr.Read
                Dim khab As New decisions(Partager.dr("id"), Partager.dr("Num_Decision"), Partager.dr("Date_Decision"), Partager.dr("Type"), Partager.dr("Resume"), Partager.dr("Declaration"), Partager.dr("Remarque"), Partager.dr("pret"))
                Me.List_decisions.Add(khab)
            End While
            Partager.dr.Close()
        End If
        Partager.close()
    End Sub

    Public Sub suprimmer_decisions(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete from Decision where id =" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_decisions()


    End Sub

    Public Sub Ajouter_decisions(ByVal dec As decisions)

        Dim s As String = "0"
        If dec.pret Then
            s = "1"
        End If
        Dim cmd As New SqlClient.SqlCommand("insert into Decision values (" & Me.id & ",@Num_Decision,@Date_Decision,@Type,@Resume,@Declaration,@Remarque,GETDATE()," & s & ")", Partager.con)

        cmd.Parameters.Add("@Num_Decision", SqlDbType.VarChar).Value = dec.Num_decision
        cmd.Parameters.Add("@Date_Decision", SqlDbType.Date).Value = dec.Date_decision
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = dec.Type
        cmd.Parameters.Add("@Resume", SqlDbType.VarChar).Value = dec.Resum
        cmd.Parameters.Add("@Declaration", SqlDbType.VarChar).Value = dec.Declamation
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = dec.Remarque

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_decisions()


    End Sub

    Public Sub modifier_decisions(ByVal dec As decisions, ByVal idd As Integer)
        Dim s As String = "0"
        If dec.pret Then
            s = "1"
        End If
        Dim cmd As New SqlClient.SqlCommand("update  Decision set Id_Dossier=@Id_Dossier,Num_Decision=@Num_Decision , Date_Decision=@Date_Decision , Type=@Type,Resume=@Resume,Declaration=@Declaration,Remarque=@Remarque,pret=" & s & " where id=" & idd, Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Num_Decision", SqlDbType.VarChar).Value = dec.Num_decision
        cmd.Parameters.Add("@Date_Decision", SqlDbType.Date).Value = dec.Date_decision
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = dec.Type
        cmd.Parameters.Add("@Resume", SqlDbType.VarChar).Value = dec.Resum
        cmd.Parameters.Add("@Declaration", SqlDbType.VarChar).Value = dec.Declamation
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = dec.Remarque



        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_decisions()

    End Sub



    Public Sub remplir_List_depences()
        Me.List_depences.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Depenses where Id_Dossier=" & Me.Id, Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Depences(Partager.dr("id"), Partager.dr("Montant_Paye"), Partager.dr("Date_Payement"), Partager.dr("Type"), Partager.dr("Num_Recus"), Partager.dr("Remarque"))
            Me.List_depences.Add(khab)
        End While
        Partager.Close()
    End Sub

    Public Sub suprimmer_depences(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete from Depenses where id=" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_depences()


    End Sub

    Public Sub Ajouter_depences(ByVal dep As Depences)


        Dim cmd As New SqlClient.SqlCommand("insert into Depenses values (@Id_Dossier,@Montant_Paye,@Date_Payement,@Type,@Num_Recus,@Remarque,GETDATE())", Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.Int).Value = Me.id
        cmd.Parameters.Add("@Montant_Paye", SqlDbType.Float).Value = dep.Montant_paye
        cmd.Parameters.Add("@Date_Payement", SqlDbType.Date).Value = dep.Date_payement
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = dep.Type
        cmd.Parameters.Add("@Num_Recus", SqlDbType.VarChar).Value = dep.Num_recu
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = dep.Remarque

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_depences()


    End Sub

    Public Sub modifier_depences(ByVal dep As Depences, ByVal idd As Integer)

        Dim cmd As New SqlClient.SqlCommand("update  Depenses set Id_Dossier=@Id_Dossier,Montant_Paye=@Montant_Paye , Date_Payement=@Date_Payement , Type=@Type,Num_Recus=@Num_Recus,Remarque=@Remarque where id=" & idd, Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Montant_Paye", SqlDbType.VarChar).Value = dep.Montant_paye
        cmd.Parameters.Add("@Date_Payement", SqlDbType.DateTime2).Value = dep.Date_payement
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = dep.Type
        cmd.Parameters.Add("@Num_Recus", SqlDbType.VarChar).Value = dep.Num_recu
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = dep.Remarque



        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_depences()

    End Sub




    Public Sub remplir_List_mo9arir()
        Dim str As String
        Me.List_mo9arir.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Mo9arir where Id_Dossier=" & Me.id, Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            str = ""
            If Partager.dr("Date_Ta3yin") Is DBNull.Value Then
                str = ""
            Else
                str = Partager.dr("Date_Ta3yin")
            End If

            Dim khab As New M9arir(Partager.dr("id"), Partager.dr("Nom"), str, Partager.dr("Remarque"), Partager.dr("Actif"))
            Me.List_mo9arir.Add(khab)
        End While
        Partager.close()
    End Sub

    Public Sub suprimmer_mo9arir(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete from Mo9arir where id= " & id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_mo9arir()
    End Sub

    Public Sub Ajouter_mo9arir(ByVal mo9 As M9arir)

        Dim cmd As New SqlClient.SqlCommand("insert into mo9arir values (@Id_Dossier,@Nom,@Date_Ta3yin,@Actif,@Remarque,GETDATE())", Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.Int).Value = Me.id
        cmd.Parameters.Add("@Nom", SqlDbType.VarChar).Value = mo9.Nom
        If String.IsNullOrEmpty(mo9.Date_ta3yin) Then
            cmd.Parameters.Add("@Date_Ta3yin", SqlDbType.Date).Value = DBNull.Value
        Else
            cmd.Parameters.Add("@Date_Ta3yin", SqlDbType.Date).Value = mo9.Date_ta3yin
        End If

        cmd.Parameters.Add("@Actif", SqlDbType.Bit).Value = 1
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = mo9.Remarque


        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_mo9arir()


    End Sub

    Public Sub modifier_mo9arir(ByVal mo9 As M9arir, ByVal idd As Integer)

        Dim cmd As New SqlClient.SqlCommand("update  Mo9arir set Id_Dossier=@Id_Dossier,Nom=@Nom , Date_Ta3yin=@Date_Ta3yin , Remarque=@Remarque  where id=" & idd, Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.Int).Value = Me.id
        cmd.Parameters.Add("@Nom", SqlDbType.VarChar).Value = mo9.Nom
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = mo9.Remarque
        If String.IsNullOrEmpty(mo9.Date_ta3yin) Then
            cmd.Parameters.Add("@Date_Ta3yin", SqlDbType.Date).Value = DBNull.Value
        Else
            cmd.Parameters.Add("@Date_Ta3yin", SqlDbType.Date).Value = mo9.Date_ta3yin
        End If
        'me.name = tarik
        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_mo9arir()

    End Sub

    Public Sub modifierMo9arirNomme(ByVal ad As M9arir)
        Dim str As String = "0"
        If ad.actif Then
            str = "1"
        End If
        Dim cmd As New SqlClient.SqlCommand("update Mo9arir set Actif=" & str _
        & "where Id=" & ad.Id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_mo9arir()
    End Sub




    Public Sub remplir_List_ijraa()
        Me.List_ijraa.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from  Ijraa where Id_Dossier=" & Me.id, Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New ijraa(Partager.dr("id"), Partager.dr("Ijraa"), Partager.dr("salle"), Partager.dr("Date_Ijraa"), Partager.dr("Responsable_Ijraa"), Partager.dr("Serveur_Ijraa"), Partager.dr("Jour"), Partager.dr("Heur"), Partager.dr("Cause"), Partager.dr("Remarque"))
            Me.List_ijraa.Add(khab)
        End While
        Partager.close()
    End Sub

    Public Sub suprimmer_ijraa(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete from Ijraa where id=" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_ijraa()


    End Sub

    Public Sub Ajouter_ijraa(ByVal ijr As ijraa)


        Dim cmd As New SqlClient.SqlCommand("insert into Ijraa values (@Id_Dossier,@Ijraa,@salle,@Date_Ijraa,@Responsable_Ijraa,@Serveur_Ijraa,@Jour,@Heur,@Cause,@Remarque,GETDATE())", Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.Int).Value = Me.Id
        cmd.Parameters.Add("@Ijraa", SqlDbType.VarChar).Value = ijr.Ijraa
        cmd.Parameters.Add("@salle", SqlDbType.VarChar).Value = ijr.Salle
        cmd.Parameters.Add("@Date_Ijraa", SqlDbType.Date).Value = ijr.Date_ijraa
        cmd.Parameters.Add("@Responsable_Ijraa", SqlDbType.VarChar).Value = ijr.Responsable_ijraa
        cmd.Parameters.Add("@Serveur_Ijraa", SqlDbType.VarChar).Value = ijr.Serveur_ijraa
        cmd.Parameters.Add("@Jour", SqlDbType.VarChar).Value = ijr.Jour
        cmd.Parameters.Add("@Heur", SqlDbType.VarChar).Value = ijr.Heure
        cmd.Parameters.Add("@Cause", SqlDbType.Text).Value = ijr.Cause
        cmd.Parameters.Add("@Remarque", SqlDbType.Text).Value = ijr.Remarque

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_ijraa()
    End Sub

    Public Sub modifier_ijraa(ByVal ijr As ijraa, ByVal idd As Integer)

        Dim cmd As New SqlClient.SqlCommand("update  Ijraa set Id_Dossier=@Id_Dossier,Ijraa=@Ijraa , salle=@salle , Date_Ijraa=@Date_Ijraa,Responsable_Ijraa=@Responsable_Ijraa ,Serveur_Ijraa=@Serveur_Ijraa,Jour=@Jour,Heur=@Heur,Cause=@Cause ,Remarque=@Remarque  where id=" & idd, Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Ijraa", SqlDbType.VarChar).Value = ijr.Ijraa
        cmd.Parameters.Add("@salle", SqlDbType.VarChar).Value = ijr.Salle
        cmd.Parameters.Add("@Date_Ijraa", SqlDbType.Date).Value = ijr.Date_ijraa
        cmd.Parameters.Add("@Responsable_Ijraa", SqlDbType.VarChar).Value = ijr.Responsable_ijraa
        cmd.Parameters.Add("@Serveur_Ijraa", SqlDbType.VarChar).Value = ijr.Serveur_ijraa
        cmd.Parameters.Add("@Jour", SqlDbType.VarChar).Value = ijr.Jour
        cmd.Parameters.Add("@Heur", SqlDbType.VarChar).Value = ijr.Heure
        cmd.Parameters.Add("@Cause", SqlDbType.VarChar).Value = ijr.Cause
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = ijr.Remarque




        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_ijraa()

    End Sub

    Public Sub remplir_List_montant()
        Me.List_montant.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Montants where Id_Dossier =" & Me.id, Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Montant(Partager.dr("id"), Partager.dr("Montant"), Partager.dr("Date"), Partager.dr("Remarque"), Partager.dr("Type"))
            Me.List_montant.Add(khab)
        End While
        Partager.close()
    End Sub

    Public Sub suprimmer_montant(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete from Montants where id =" & id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_montant()


    End Sub

    Public Sub Ajouter_montant(ByVal mnt As Montant)

        Dim cmd As New SqlClient.SqlCommand("insert into Montants values (@Id_Dossier,@Montant,@Date,@Type,@Remarque,GETDATE())", Partager.con)

        cmd.Parameters.Add("@Id_Dossier", SqlDbType.Int).Value = Me.id
        cmd.Parameters.Add("@Montant", SqlDbType.Float).Value = mnt.Montant
        cmd.Parameters.Add("@Date", SqlDbType.Date).Value = mnt.Date_payement
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = mnt.Type
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = mnt.Remarque


        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_montant()


    End Sub


    Public Sub remplir_List_avocat_enemie()
        Me.List_avocat_enemie.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Dossier_Avocat_Adversaire  where  Id_Dossier =" & Me.id, Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Dossier_Avocat_Adversaire(Partager.dr("Id_Avocat_Adversaire"), Partager.dr("nomme"))
            Me.List_avocat_enemie.Add(khab)
        End While
        Partager.close()
    End Sub

    Public Sub suprimmer_avocat_enemie(ByVal idd As Dossier_Avocat_Adversaire)

        Dim cmd As New SqlClient.SqlCommand("delete  Dossier_Avocat_Adversaire where Id_Dossier=" & Me.id & " and Id_Avocat_Adversaire=" & idd.Id_Avocat_Adversaire, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_avocat_enemie()
    End Sub

    Public Sub Ajouter_avocat_enemie(ByVal idd As Dossier_Avocat_Adversaire)

        Dim cmd As New SqlClient.SqlCommand("insert into Dossier_Avocat_Adversaire values(" & Me.id & "," & idd.Id_Avocat_Adversaire & ",1,GETDATE())", Partager.con)
        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_avocat_enemie()
    End Sub

    Public Sub modifierAvoEnemNomme(ByVal ad As Dossier_Avocat_Adversaire)
        Dim str As String = "0"
        If ad.nomme Then
            str = "1"
        End If
        Dim cmd As New SqlClient.SqlCommand("update Dossier_Avocat_Adversaire set nomme=" & str _
        & "where Id_Avocat_Adversaire= " & ad.Id_Avocat_Adversaire & "and Id_Dossier=" & Me.id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_avocat_enemie()
    End Sub




    Public Sub remplir_List_Dos_Avo_Bur_Mokh(ByVal Id_Avo_Doss As Integer)
        Me.List_Mokhabara.Clear()
        Dim cmd As New SqlClient.SqlCommand("select *  from " & _
       "dossier_Avocat_Mokhabara  where Id_Avo_Doss=" & Id_Avo_Doss, Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader

        Dim khab As dossier_Avocat_Mokhabara
        If Partager.dr.HasRows Then
            While Partager.dr.Read
                khab = New dossier_Avocat_Mokhabara(Partager.dr("Id_Avocat_Mokhabara"), _
                Partager.dr("id_Avo_Doss"), Partager.dr("nomme"))
                Me.List_Mokhabara.Add(khab)
            End While
        End If
        Partager.close()
    End Sub
    Public Sub suprimmer_Dos_Avo_Bur_Mokh(ByVal dossAvoMokh As dossier_Avocat_Mokhabara)

        Dim cmd As New SqlClient.SqlCommand("delete from dossier_Avocat_Mokhabara where Id_Avocat_Mokhabara=" & dossAvoMokh.Id_Avocat_Mokh, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_Dos_Avo_Bur_Mokh(dossAvoMokh.Id_Avo_Doss)
    End Sub
    Public Sub Ajouter_Dos_Avo_Bur_Mokh(ByVal khib As dossier_Avocat_Mokhabara)
        Dim cmd As New SqlClient.SqlCommand("insert into dossier_Avocat_Mokhabara values" & _
        " (@Id_Avocat_Mokhabara,@Id_Avo_Doss,1,GETDATE())", Partager.con)


        cmd.Parameters.Add("@Id_Avocat_Mokhabara", SqlDbType.Int).Value = khib.Id_Avocat_Mokh
        cmd.Parameters.Add("@Id_Avo_Doss", SqlDbType.Int).Value = khib.Id_Avo_Doss

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
        Me.remplir_List_Dos_Avo_Bur_Mokh(khib.Id_Avo_Doss)
    End Sub
    Public Sub modifierAvoMokhNomme(ByVal ad As dossier_Avocat_Mokhabara)
        Dim str As String = "0"
        If ad.nomme Then
            str = "1"
        End If

        Dim cmd As New SqlClient.SqlCommand("update dossier_Avocat_Mokhabara set nomme=" & str _
        & "where id_Avo_Doss= " & ad.Id_Avo_Doss, Partager.con)
        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
        remplir_List_avocat_bureau()
    End Sub


    Public Sub Ajouter_avocat_bureau(ByRef ad As dossAvoBur)
        Dim cmd As New SqlClient.SqlCommand _
    ("insert into Dossiers_Avocat_Bureau output inserted.id values(" & Me.id & "," & _
    ad.idAvoBur & ",1,GETDATE())", Partager.con)

        Partager.open()
        ad.id = cmd.ExecuteScalar
        Partager.close()

        remplir_List_avocat_bureau()
    End Sub
    Public Sub remplir_List_avocat_bureau() ' remplit ma list avec des objet de type dossAvoBur
        Me.List_avocat_bureau.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Dossiers_Avocat_Bureau where  Id_Dossier =" & _
        Me.id, Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New dossAvoBur(Partager.dr("Id_Dossier"), Partager.dr("Id_Avocat_Bureau"), _
                                       Partager.dr("nomme"))
            khab.id = Partager.dr("id")
            Me.List_avocat_bureau.Add(khab)
        End While
        Partager.close()
    End Sub
    Public Sub suprimmer_avocat_bureau(ByVal id As Integer) 'Faire entrer l'id qui est la clé primaire de la table
        Dim cmd As New SqlClient.SqlCommand _
        ("delete From  Dossiers_Avocat_Bureau  where  Id =" & id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_avocat_bureau()
    End Sub


   


    Public Sub remplir_List_temoins()
        Me.List_temoins.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Dossier_temoins where  Id_Dossier =" & Me.id, Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Dossier_temoins(Partager.dr("id_Dossier"), Partager.dr("Id_temoins"))
            Me.List_temoins.Add(khab)
        End While
        Partager.close()
    End Sub

    Public Sub suprimmer_temoins(ByVal cd As Dossier_temoins)

        Dim cmd As New SqlClient.SqlCommand("delete  Dossier_temoins where Id_temoins =" & cd.Id_temoins & " and Id_Dossier =" & Me.id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_temoins()


    End Sub

    Public Sub Ajouter_temoins(ByVal cd As Dossier_temoins)

        Dim cmd As New SqlClient.SqlCommand("insert into Dossier_temoins values(" & Me.id & "," & cd.Id_temoins & ",GETDATE())", Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_temoins()


    End Sub

    '-------------------------------------

    Public Sub remplir_List_Dos_Avo_Avd_Mokh(ByVal id As Integer)
        Me.List_Mokhabara.Clear()
        Dim cmd As New SqlClient.SqlCommand("select *  from Avocat_Mokhabara_Avocat_Adversaire  where Id_Dossier=" & Me.id & " and Id_Avocat_Adversaire=" & id, Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader

        Dim khab As Avocat_Mokhabara_Avocat_Adversaire
        If Partager.dr.HasRows Then
            While Partager.dr.Read
                khab = New Avocat_Mokhabara_Avocat_Adversaire(Partager.dr("Id_Avocat_Mokhabara"), Partager.dr("Id_Avocat_Adversaire"), Partager.dr("nomme"))
                Me.List_Mokhabara.Add(khab)
            End While
        End If
        Partager.close()
    End Sub
    Public Sub suprimmer_Dos_Avo_Adv_Mokh(ByVal dossAvoMokh As Avocat_Mokhabara_Avocat_Adversaire)

        Dim cmd As New SqlClient.SqlCommand("delete from Avocat_Mokhabara_Avocat_Adversaire where Id_Dossier=" & Me.id & " and Id_Avocat_Mokhabara=" & dossAvoMokh.Id_Avocat_Mokhabara & " and Id_Avocat_Adversaire=" & dossAvoMokh.Id_Avocat_Adversaire, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_Dos_Avo_Bur_Mokh(dossAvoMokh.Id_Avocat_Adversaire)
    End Sub
    Public Sub Ajouter_Dos_Avo_Adv_Mokh(ByVal khib As Avocat_Mokhabara_Avocat_Adversaire)
        Dim cmd As New SqlClient.SqlCommand("insert into Avocat_Mokhabara_Avocat_Adversaire values(" & Me.id & "," & khib.Id_Avocat_Mokhabara & "," & khib.Id_Avocat_Adversaire & ",1,GETDATE())", Partager.con)
        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_Dos_Avo_Avd_Mokh(khib.Id_Avocat_Adversaire)
    End Sub
    Public Sub modifierAvoAdvMokhNomme(ByVal ad As Avocat_Mokhabara_Avocat_Adversaire)
        Dim str As String = "0"
        If ad.nomme Then
            str = "1"
        End If
        Dim cmd As New SqlClient.SqlCommand("update Avocat_Mokhabara_Avocat_Adversaire set nomme=" & str _
        & " where Id_Dossier= " & Me.id & " and Id_Avocat_Adversaire= " & ad.Id_Avocat_Adversaire & " and Id_Avocat_Mokhabara= " & ad.Id_Avocat_Mokhabara, Partager.con)
        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
        remplir_List_avocat_bureau()
    End Sub

    Public Sub modifierRefDossier(ByVal Ref As Integer)
        Dim cmd As New SqlClient.SqlCommand("update Dossier set Ref=" & Ref & " Where Id = " & Me.id, Partager.con)
        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
    End Sub
End Class
